package cn.wq.xa.controller;

import cn.wq.xa.entity.User;
import cn.wq.xa.mapper.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserDao userDao;

    @RequestMapping(value = "/hello", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String getHello() {
        return "Hello,Word!!!";
    }

    @RequestMapping(value = "/userList", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public List<User> getUserList() {
        return userDao.ListUser();
    }

    @RequestMapping(value = "/insertU", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public int insert(User user) {
        return userDao.insertUser(user);
    }

    @RequestMapping(value = "/deleteU", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public int insert(int id) {
        return userDao.delete(id);
    }

    @RequestMapping(value = "/updateU", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public int update(User user) {
        return userDao.update(user);
    }

    @RequestMapping(value = "/findUser", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public User update(int id) {
        return userDao.findUser(id);
    }
}
